﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HsTec.Mobile.Green.SqlServerDAL;
using Baimasoft.Web.UI;

public partial class BaseData_NetWorkManage : Baimasoft.Web.UI.PageManagerTop
{
    Machineroom machineroom = new Machineroom();
    Area area = new Area();
    Network MyNW = new Network();
    
    protected void Page_Load(object sender, EventArgs e)
    {
        this.BindControlEvent();
        this.HiddenID.Value = "";
        if (!this.IsPostBack)
        {
            try
            {
                Indicator.Text = Request.QueryString["sIndicator"].ToString();
            }
            catch
            {
            }
            GridView1.Attributes.Add("BorderColor", "LightSkyBlue");
            this.SDT.Text = DateTime.Now.ToString("yyyy-MM") + "-01";
            this.EDT.Text = DateTime.Now.ToString("yyyy-MM-dd");
            ddlRegionDataBind();
            ddlMachineDataBind();
            this.BindGridViewData();//绑定GridView,为删除服务
        }
    }

    protected override void BindGridViewData()
    {
        this.DataSource = MyNW .GetNetWorks (GetSearchString());

        this.DataSource.DefaultView.Sort = this.SortString;
        GridView1.DataSource = this.DataSource.DefaultView;
        GridView1.DataBind();

    }

    /// <summary>
    /// 区域下拉框
    /// </summary>
    protected void ddlRegionDataBind()
    {
        ddlRegionid.DataSource = area.GetAreaInfos(string.Empty);
        ddlRegionid.DataBind();
        ddlRegionid.Items.Insert(0, "全部");
        ddlRegionid.Items[0].Value = "0";
    }

    /// <summary>
    /// 机房下拉框绑定
    /// </summary>
    protected void ddlMachineDataBind()
    {
        ddlMachineid.DataSource = machineroom.GetMachineRooms("");
        ddlMachineid.DataBind();
        ddlMachineid.Items.Insert(0, "全部");
        ddlMachineid.Items[0].Value = "0";
    }

    protected override void Delete(string ids)
    {
        try
        {
            int iback = MyNW .DeleteNetWork (ids);
            if (iback < 1)
            {
                Baimasoft.Web.UI.Message.AlertMsg(this, "没有可删除的数据!");
                return;
            }
            else
            {
                Baimasoft.Web.UI.Message.AlertMsg(this, "删除成功!");
                return;
            }
        }
        catch
        {
            Baimasoft.Web.UI.Message.AlertMsg(this, "删除失败!");
        }
    }

    protected override string GetSearchString()
    {
        string searchStr = "(1=1)";

        if (this.txtNetwName.Text.Trim().Length > 0)
        {
            searchStr += " and  netw_name like '%" + this.txtNetwName.Text + "%' ";
        }

        string sddlRegionid = ddlRegionid.SelectedValue.ToString().Trim();
        if (sddlRegionid != "0")
        {
            searchStr += " and a.region_id ='" + sddlRegionid + "' ";
        }
        if (ddlMachineid.SelectedValue.ToString().Trim() != "0")
        {
            searchStr += " and a.mroom_id ='" + ddlMachineid.SelectedValue.ToString().Trim() + "' ";
        }

        if (this.SDT.Text.ToString().Trim() != "")
        {
            searchStr += " and convert(varchar(10),a.netw_createdate,120) >= '" + this.SDT.Text.ToString().Trim() + "' ";
        }
        else
        {
            searchStr += " and convert(varchar(10),a.netw_createdate,120) >= '" + DateTime.Now.ToString("yyyy-MM-dd") + "' ";
        }
        if (this.EDT.Text.ToString().Trim() != "")
        {
            searchStr += " and convert(varchar(10),a.netw_createdate,120) <= '" + this.EDT.Text.ToString().Trim() + "' ";
        }
        else
        {
            searchStr += " and convert(varchar(10),a.netw_createdate,120) <= '" + DateTime.Now.ToString("yyyy-MM-dd") + "' ";
        }

        return searchStr;
    }
}


